#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : Wed Mar 06 2019
# @Author  : xujunfu (xjf891121@gmail.com})
# @Link    : http://junfuxu.github.io/
import os

import pymysql

from .settings import *

from receiver.config import MONGO, MEDIA_UPLOADS_PATH

pymysql.install_as_MySQLdb()

ALLOWED_HOSTS = ['*']

# App
INSTALLED_APPS += [
    'simpleui',
    'user',
    'location',
    'terminal',
    'company',
    'alarm',
    'media',
    'corsheaders',
    'rest_framework',
    'django_filters',
    'rest_framework.authtoken',
    'django_crontab'
]

MIDDLEWARE += [
    'corsheaders.middleware.CorsMiddleware',
    'django.middleware.common.CommonMiddleware',  # 注意顺序
]

# 时间配置

LANGUAGE_CODE = 'zh-hans'

TIME_ZONE = 'Asia/Shanghai'

USE_I18N = True

USE_L10N = True

USE_TZ = False

AUTH_USER_MODEL = "user.User"

# rest 配置
REST_FRAMEWORK = {
    # Use Django's standard `django.contrib.auth` permissions,
    # or allow read-only access for unauthenticated users.
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
    ),
    'DEFAULT_PAGINATION_CLASS': 'utils.pagination.VCTPagination',
    'DEFAULT_FILTER_BACKENDS': ('django_filters.rest_framework.DjangoFilterBackend', 'rest_framework.filters.SearchFilter'),
    'PAGE_SIZE': 10,
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework.authentication.TokenAuthentication',
    ),
    'DATETIME_FORMAT': "%Y-%m-%d %H:%M:%S",
    'COERCE_DECIMAL_TO_STRING': False,
}

APPEND_SLASH = False
UPLOAD_PATH = 'uploads/'
MEDIA_URL = '/'

# 跨域增加忽略
CORS_ALLOW_CREDENTIALS = True
CORS_ORIGIN_ALLOW_ALL = True
# if ENV == 'product':
#     CORS_ORIGIN_WHITELIST = (
#         '*',
#     )
# else:
#     CORS_ORIGIN_WHITELIST = (
#         '*',
#     )

CORS_ALLOW_METHODS = (
    'DELETE',
    'GET',
    'OPTIONS',
    'PATCH',
    'POST',
    'PUT',
    'VIEW',
)

CORS_ALLOW_HEADERS = (
    'XMLHttpRequest',
    'X_FILENAME',
    'accept-encoding',
    'authorization',
    'content-type',
    'accept',
    'dnt',
    'origin',
    'user-agent',
    'x-csrftoken',
    'x-requested-with',
    'Pragma',
)

# 首页显示服务器、python、django、simpleui相关信息
SIMPLEUI_HOME_INFO = False

# 添加定时任务
CRONJOBS = [
    # ('*/1 * * * *', 'zsh_api.zsh_location.run'),
    # ('*/1 * * * *', 'zsh_api.zsh_warn.run'),
    ('*/3 * * * *', 'media.video_crontab.close_video_uri'),
]
CRONTAB_COMMAND_PREFIX = 'LANG_ALL=zh_cn.UTF-8'

